package cn.kgcnews.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

public class CheckCodeServlet extends HttpServlet {


	
	private static final long serialVersionUID = 1L;

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
	//获取服务器端存储验证码的session
		String imgCode = (String)request.getSession().getAttribute("imgcode");
		//获取用户填写的验证码
		String inputCode = request.getParameter("code");
		HashMap<String,String> map=new HashMap<String, String>();
		if(imgCode.equalsIgnoreCase(inputCode)){
			map.put("result", "验证码不正确");
			System.out.println("验证码不正确");
		}else{
			map.put("result", "验证码正确");
			System.out.println("验证码正确");
		}
		out.print(JSON.toJSONString(map));
		out.flush();
		out.close();
	}

	
	public void init() throws ServletException {
		// Put your code here
	}

}
